#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N = 1e5 + 10;
int n = 1e5 + 10;
int x , y;
int disc[N];
void bfs()
{
	queue<int> q;
	q.push(x);
	disc[x] = 0;
	while(q.size())
	{
		auto t = q.front();q.pop();
		int a = t + 1 , b = t - 1 , c = t * 2;
		if(a <= n && disc[a] == -1)
		{
			q.push(a);
			disc[a] = disc[t] + 1;
		}
		if(b > 0 && disc[b] == -1)
		{
			q.push(b);
			disc[b] = disc[t] + 1;
		}
		if(c <= n && disc[c] == -1)
		{
			q.push(c);
			disc[c] = disc[t] + 1;
		}
		
		if(a == y || b == y || c == y) return;
	}
}
int main()
{
	int T;cin >> T;
	while(T--)
	{
		memset(disc,-1,sizeof disc);
		
		cin >> x >> y;
		bfs();
		cout << disc[y] << endl; 
	}
	return 0;
}
 
